//
//  OrderCarCell.m
//  BaseProject
//
//  Created by 王洋 on 2021/5/13.
//  Copyright © 2021 王洋. All rights reserved.
//
#import "WeddingCarSkuView.h"
#import "OrderCarCell.h"

@interface OrderCarCell ()

@property (nonatomic, strong) WeddingCarSkuView *skuView;

@end

@implementation OrderCarCell

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.skuBGView addSubview:self.skuView];
    [self.skuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
}

+(CGFloat)calculateHeightWithModel:(WeddingCarCartModel *)model {
    CGFloat skuToTop = 14+16+5;
    
    NSInteger count = 1;
    if (model.userShoppingCarDetailList.count > count) {
        count = model.userShoppingCarDetailList.count;
    }
    CGFloat skuHeight = 16 * count;
    CGFloat toBottom = 30;
    return skuToTop + skuHeight + toBottom;
}

- (void)fillCellWithModel:(WeddingCarCartModel *)model {

    [self.packageMainImageView sd_setImageWithURL:[NSURL URLWithString:model.specImg]];
    
    self.packageMainTitleLab.text = model.specName;
    self.packagePriceLab.text = [NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.totalPrice]];
    
    self.countLab.text = [NSString stringWithFormat:@"x%ld",model.goodsNum];
    
    [self.skuView fillViewWithArray:model.userShoppingCarDetailList andFollowNum:model.goodsNum];
    self.skuHeightConstrain.constant = 16*model.userShoppingCarDetailList.count;
    
    //如果是套餐的时候
    if ([model.goodsMold isEqualToString:@"1"]) {
        self.countLab.hidden = YES;
    }else if ([model.goodsMold isEqualToString:@"3"]) {
        self.countLab.hidden = NO;
    }
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.packageMainImageView pp_clipCorners:UIRectCornerAllCorners radius:8];
    });

}

- (WeddingCarSkuView *)skuView {
    if (!_skuView) {
        _skuView = [[WeddingCarSkuView alloc] init];
    }
    return _skuView;
}

@end
